package com.xpc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xpc.controller.utils.R;
import com.xpc.pojo.User;
import com.xpc.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Project：CourseProject
 * Date：2022/4/13
 * Time：23:29
 * Description：user表现层REST开发风格
 *
 * @author 南北辰的键盘
 * @version 1.0
 */

@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private IUserService iUserService;

    @GetMapping
    public R getAll(){
        return new R (true,iUserService.list());
    }

    @PostMapping
    public R save(@RequestBody User user){
        return new R(iUserService.save(user)) ;
    }

    @PutMapping
    public R update(@RequestBody User user){
        return new R(iUserService.updateById(user));
    }

    @DeleteMapping("{id}")
    public R delete(@PathVariable int id){
        return new R(true,iUserService.removeById(id));
    }

    @GetMapping("{id}")
    public R getById(@PathVariable int id){
        return new R(true,iUserService.getById(id));
    }

    @GetMapping("{currentPage}/{pageSize}")
    public R getPage(@PathVariable int currentPage,@PathVariable int pageSize){
        return new R(true,iUserService.getPage(currentPage,pageSize));
    }

}
